package com.chak.voyage.service;

import com.chak.voyage.data.dao.IDuplicateDao;
import com.chak.voyage.data.dao.INoteDao;
import com.chak.voyage.data.entity.TDuplicate;
import com.chak.voyage.data.entity.TDuplicateExample;
import com.chak.voyage.data.entity.TNote;
import com.chak.voyage.data.entity.TNoteExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by delzh on 2016/9/8.
 */
@Service
public class DataService {

    @Autowired
    private INoteDao iNoteDao;

    @Autowired
    private IDuplicateDao iDuplicateDao;

    /**
     * 获取指定type的所有note
     * @param type
     * @return
     */
    public List<TNote> getAllNoteByType(Integer type){
        TNoteExample tNoteExample = new TNoteExample();
        tNoteExample.createCriteria()
                .andTypeEqualTo(type);
        return iNoteDao.selectByExample(tNoteExample);
    }

    public List<TDuplicate> getAllDuplicate(int priority) {
        TDuplicateExample tDuplicateExample = new TDuplicateExample();
        tDuplicateExample.createCriteria()
                .andTypeGreaterThanOrEqualTo(priority);
        return iDuplicateDao.selectByExample(tDuplicateExample);
    }

    public void addDuplicate(String url,Integer type) {
        TDuplicate tDuplicate = new TDuplicate();
        tDuplicate.setUrl(url);
        tDuplicate.setType(type);
        iDuplicateDao.insert(tDuplicate);
    }
}
